# coding=utf-8
html_doc = """
<html><head><title>The Dormouse's story</title></head>

<p class="title"><b>The Dormouse's story</b></p>

<p class="story">
    Once upon a time there were three little sisters; and their names were
    <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
    <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
    <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
    and they lived at the bottom of a well.
</p>

<p class="story">...</p>
"""

from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc)
p = soup('p')

for i in p:
    if i.has_attr('class'):
        print 'has'
    else:
        print 'no'
# print dir(p[0])
'''
['HTML_FORMATTERS', 'XML_FORMATTERS', '__call__', '__class__', '__contains__',
__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__
etattr__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__
, '__len__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '_
reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__'
 '__subclasshook__', '__unicode__', '__weakref__', '_all_strings', '_attr_value
as_string', '_attribute_checker', '_find_all', '_find_one', '_formatter_for_nam
', '_is_xml', '_lastRecursiveChild', '_last_descendant', '_select_debug', '_sel
ctor_combinators', '_should_pretty_print', '_tag_name_matches_and', 'append', '
ttribselect_re', 'attrs', 'can_be_empty_element', 'childGenerator', 'children',
'clear', 'contents', 'decode', 'decode_contents', 'decompose', 'descendants', '
ncode', 'encode_contents', 'extract', 'fetchNextSiblings', 'fetchParents', 'fet
hPrevious', 'fetchPreviousSiblings', 'find', 'findAll', 'findAllNext', 'findAll
revious', 'findChild', 'findChildren', 'findNext', 'findNextSibling', 'findNext
iblings', 'findParent', 'findParents', 'findPrevious', 'findPreviousSibling', '
indPreviousSiblings', 'find_all', 'find_all_next', 'find_all_previous', 'find_n
xt', 'find_next_sibling', 'find_next_siblings', 'find_parent', 'find_parents',
find_previous', 'find_previous_sibling', 'find_previous_siblings', 'format_stri
g', 'get', 'getText', 'get_text', 'has_attr', 'has_key', 'hidden', 'index', 'in
ert', 'insert_after', 'insert_before', 'isSelfClosing', 'is_empty_element', 'na
e', 'namespace', 'next', 'nextGenerator', 'nextSibling', 'nextSiblingGenerator'
 'next_element', 'next_elements', 'next_sibling', 'next_siblings', 'parent', 'p
rentGenerator', 'parents', 'parserClass', 'parser_class', 'prefix', 'prettify',
'previous', 'previousGenerator', 'previousSibling', 'previousSiblingGenerator',
'previous_element', 'previous_elements', 'previous_sibling', 'previous_siblings
, 'recursiveChildGenerator', 'renderContents', 'replaceWith', 'replaceWithChild
en', 'replace_with', 'replace_with_children', 'select', 'setup', 'string', 'str
ngs', 'stripped_strings', 'tag_name_re', 'text', 'unwrap', 'wrap']

'''